﻿using DefaultDspPlugins.UI.Common.Modulizer.Engine.GUIv2.FrontEndComponents;
using SharpDepend.Datatypes;
using ZquenceStudio3Host.Graphics.Components;
using ZquenceStudio3Host.Graphics.GUI;

namespace DefaultDspPlugins.UI.Common.Modulizer.Engine.GUIv2.Editors
{
    internal class PanelUIEditorWindow : BaseUIEditorWindow
    {
        private Panel mCurrentPanelUI;
        private PropertiesEditor Properties;
        private ZoomablePanel ModuleUIViewer;

        public PanelUIEditorWindow(BasicGuiManager engineCore) : base(engineCore)
        {
        }

        public Panel CurrentPanelUI
        {
            get { return mCurrentPanelUI; }
            set
            {
                mCurrentPanelUI = value;

                ModuleUIViewer.Content = value;

                UpdateProperties(value);
            }
        }

        protected override void OnComponentInitialize()
        {
            Properties = new PropertiesEditor(EngineCore);
            Properties.PropertyChanged += Properties_PropertyChanged;
            Properties.BackgroundColor = new SharpDepend.Datatypes.Color(253, 60, 60, 60);
            Properties.DimensionInProcent = true;
            Properties.X = 0;
            Properties.Width = 20;
            Properties.Height = 100;
            AddPart(Properties);

            ModuleUIViewer = new ZoomablePanel(EngineCore);
            ModuleUIViewer.BackgroundColor = Color.DarkGray;
            //ModuleUIViewer.SetTexture("Images/TextilBackgroundBlack.png");
            ModuleUIViewer.DimensionInProcent = true;
            ModuleUIViewer.X = 20;
            ModuleUIViewer.Width = 80;
            ModuleUIViewer.Height = 100;
            AddPart(ModuleUIViewer);
        }

        private void UpdateProperties(BaseObject moduleUI)
        {
            Properties.EditablePanel = moduleUI;
        }

        private void Properties_PropertyChanged()
        {
            // TODO: Save properties...

            //ModuleUIUpdated?.Invoke(mCurrentModuleUI.ModuleUI);
        }

    }
}
